/*
 * Copyright   2000   The Regents of the University of California
 * All Rights Reserved
 * 
 * Permission to use, copy, modify and distribute any part of Simgrid/SG
 * for educational, research and non-profit purposes, without fee, and
 * without a written agreement is hereby granted, provided that the above
 * copyright notice, this paragraph and the following three paragraphs
 * appear in all copies.
 * 
 * Those desiring to incorporate this Simgrid/SG into commercial
 * products or use for commercial purposes should contact the Technology
 * Transfer & Intellectual Property Services, University of California,
 * San Diego, 9500 Gilman Drive, Mail Code 0910, La Jolla, CA 92093-0910,
 * Ph: (858) 534-5815, FAX: (858) 534-7345, E-MAIL:invent@ucsd.edu.
 * 
 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
 * INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS Simgrid/SG,
 * EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY
 * OF SUCH DAMAGE.  
 * 
 * THE Simgrid/SG PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND THE
 * UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
 * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.  THE UNIVERSITY OF
 * CALIFORNIA MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY
 * KIND, EITHER IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
 * PURPOSE, OR THAT THE USE OF THE Simgrid/SG WILL NOT INFRINGE ANY
 * PATENT, TRADEMARK OR OTHER RIGHTS.
 */

#ifndef SIMGRID_H
#define SIMGRID_H

#ifdef __cplusplus
extern "C" {
#endif


#include "simgrid_config.h"

#include "sg_types.h"
#include "sg_datastructures.h"
#include "sg_prototypes.h"
#include "sg_global.h"
#include "sg_random.h"

/*********************/
/* GENERAL FUNCTIONS */
/*********************/

  void SG_init(void);
  void SG_reset(void);
  void SG_clear(void);
  void SG_clearTasks(void);
  void SG_clearResources(void);
  long double SG_getClock(void);
  void SG_setEpsilon(long double epsilon);


/******************/
/* TASK FUNCTIONS */
/******************/


/* general */
  SG_Task SG_newTask(SG_task_t type, const char *name, long double cost,
		     void *metadata);
  void *SG_getTaskMetadata(SG_Task task);
  const char *SG_getTaskName(SG_Task task);
  long double SG_getTaskCost(SG_Task task);
  long double SG_getTaskCostRemaining(SG_Task task);
  void SG_setTaskPriority(SG_Task task, long double priority);
  long double SG_getTaskPriority(SG_Task task);
  SG_task_t SG_getTaskType(SG_Task task);
  void SG_suspendTask(SG_Task task);
  void SG_resumeTask(SG_Task task);
  int SG_suspendedTask(SG_Task task);

/* dependencies */
  int SG_addDependency(SG_Task child, SG_Task parent);
  int SG_removeDependency(SG_Task child, SG_Task parent);
  int SG_removeAllDependencies(SG_Task child);
  SG_Task *SG_getTaskParents(SG_Task child);
  SG_Task *SG_getTaskChildren(SG_Task parent);

  int SG_clearAllDependencies(void);

/* life cycle */
  SG_taskstate_t SG_getTaskState(SG_Task task);
  SG_Resource SG_getTaskResource(SG_Task task);
  int SG_getStateDistribution(int *num_tasks_unscheduled,
			      int *num_tasks_scheduled,
			      int *num_tasks_ready,
			      int *num_tasks_running,
				  int* num_tasks_failed,
				  int *num_task_done);

/* audit */
  long double SG_getTaskStartTime(SG_Task task);
  long double SG_getTaskFinishTime(SG_Task task);

/* clear */
  void SG_clearTask(SG_Task task);
  void SG_readyTask(SG_Task task);

/**********************/
/* RESOURCE FUNCTIONS */
/**********************/

/* general */
 SG_Resource SG_newHost(const char *name, long double rel_speed,
			 SG_resourcesharing_t policy,
			 const char *cpu_avail, 
			 long double cpu_offset,
			 long double fixed_cpu,
			 const char *failure_trace, 
			 long double (*failure_function)(long double),
			 long double fixed_failure,
			 void *metadata);


  SG_Resource SG_newLink(const char *name, SG_resourcesharing_t policy,
			 const char *latency, long double latency_offset,
			 long double fixed_latency, const char *bandwidth,
			 long double bandwidth_offset, long double fixed_bandwidth,
			 const char *max_bandwidth, long double max_bandwidth_offset, 
			 long double max_fixed_bandwidth, void *metadata);
  
  SG_Resource SG_newTCPLink(const char *name, char *latency, 
                            long double latency_offset, long double fixed_latency,
                            const char *bandwidth, long double bandwidth_offset, 
                            long double fixed_bandwidth, long double alpha,
 			    const char *max_bandwidth, long double max_bandwidth_offset, 
			    long double max_fixed_bandwidth, void *metadata);
    
  SG_Resource SG_newTCPRoute(const char *name, SG_Resource *links, 
                             void *metadata);
  void *SG_getResourceMetadata(SG_Resource resource);
  const char *SG_getResourceName(SG_Resource resource);
  SG_resource_t SG_getResourceType(SG_Resource resource);

  long double SG_getHostRelSpeed(SG_Resource resource);

  long double SG_getHostLoad(SG_Resource resource, long double t);
  long double SG_getLinkLatency(SG_Resource resource, long double t);
  long double SG_getLinkBandwidth(SG_Resource resource, long double t);
  long double SG_getLinkMaxBandwidth(SG_Resource resource, long double t);


/************************/
/* SCHEDULING FUNCTIONS */
/************************/

/* scheduling */
  int SG_scheduleTaskOnResource(SG_Task task, SG_Resource resource);
  int SG_unScheduleTask(SG_Task task);
  SG_Task *SG_unScheduleAllTasksOnResource(SG_Resource resource);
/* info */
  SG_Task *SG_getTasksScheduledOnResource(SG_Resource resource);
  SG_Task *SG_getTasksRunningOnResource(SG_Resource resource);
  SG_Task *SG_getTasksFailedOnResource(SG_Resource resource);

/*************************/
/* PREDICTIONS FUNCTIONS */
/*************************/

  long double SG_getPrediction(SG_prediction_t type,
			  long double attribute,
			  long double (*error) (long double time,
					   long double amount,
					   long double attribute),
			  SG_Resource resource,
			  long double when, long double amount);


/***************************/
/* RANDOM NUMBER FUNCTIONS */
/***************************/

  void SG_srand(unsigned int offset);
  int SG_rand(void);


/***********************/
/* SIMULATION FUNCTION */
/***********************/

  SG_Task *SG_simulate(long double how_long,
		       SG_Task task_to_watch, SG_outputmode_t output_mode);


#ifdef __cplusplus
}
#endif
#endif				/* SIMGRID_H */
